<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //总订单表
        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('enterprise_id') ->default(0)->comment('所属企业');
            $table->string('order_num')->unique()                    ->comment('订单号');
            $table->bigInteger('user_id')           ->default(0)->comment('下单用户');
            $table->bigInteger('merchant_id')       ->default(0)->comment('所属店铺');
            $table->bigInteger('order_address_id')  ->default(0)->comment('订单地址id');
            $table->decimal('original_price')       ->default(0)->comment('原始价格');
            $table->decimal('discount_price')       ->default(0)->comment('优惠后价格');
            $table->decimal('delivery_fee')         ->default(0)->comment('配送费');
            $table->string('discount_name')         ->default('')->comment('折扣名称');
            $table->integer('coupon_id')            ->default(0)->comment('优惠券id');
            $table->decimal('coupon_reduce_price')  ->default(0)->comment('优惠券减的金额');
            $table->decimal('pay_amount')           ->default(0)->comment('订单实际成交价格');
            $table->timestamp('pay_time')           ->nullable()      ->comment('支付时间');
            $table->string('pay_way')               ->nullable()      ->comment('支付方式：wechatpay,alipay,unionpay');
            $table->integer('is_pay')               ->default(0)->comment('是否支付');
            $table->string('express_num',100)->nullable()      ->comment('配送单号');
            $table->string('express')               ->nullable()      ->comment('快递公司');
            $table->timestamp('express_time')       ->nullable()      ->comment('发货时间');
            $table->string('delivery_method')       ->nullable()      ->comment('收货方式');
            $table->string('remark')                ->default('')->comment('备注');
            $table->integer('status')               ->default(0)->comment('订单状态：1待支付、2待发货、3待收货、4已完成,5申请取消，6已取消');
            $table->string('agent_phone_number')    ->nullable()->comment('客服手机号');
            $table->string('agent_email')           ->nullable()->comment('客服邮箱');
            $table->softDeletes();
            $table->timestamps();
        });
        //子订单表
        Schema::create('order_item', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('自增id');
            $table->bigInteger('order_id')                  ->default(0)->comment('订单id');
            $table->bigInteger('merchant_medicine_id')      ->default(0)->comment('药品id');
            $table->bigInteger('merchant_medicine_spu_id')  ->default(0)->comment('商品属性id');
            $table->string('item_num')                      ->nullable()      ->comment('子订单编号');
            $table->decimal('original_price')               ->default(0)->comment('商品原始单价');
            $table->decimal('discount_price')               ->default(0)->comment('商品优惠后单价');
            $table->integer('num')                          ->default(0)->comment('购买数量');
            $table->decimal('total_amount')                 ->default(0)->comment('实际成交总价格');
            $table->integer('goods_snapshot_id')            ->default(0)->comment('快照id');
            $table->softDeletes();
            $table->timestamps();
        });
        //订单发货地址表
        Schema::create('order_address', function(Blueprint $table) {
            $table->bigIncrements('id')->comment('地址标识');
            $table->bigInteger('user_id')->default(0)->comment('用户标识');
            $table->string('consignee')  ->default('')->comment('收件人');
            $table->string('province')   ->default('')->comment('省份');
            $table->string('city')       ->default('')->comment('城市');
            $table->string('area')       ->default('')->comment('地区');
            $table->string('address')    ->default('')->comment('详细地址');
            $table->string('postcode')   ->default('')->comment('邮政编码');
            $table->string('phone')      ->default('')->comment('手机号');
            $table->softDeletes();
            $table->timestamps();
        });

        //商品快照表
        Schema::create('medicine_snapshot', function(Blueprint $table) {
            $table->increments('id')->comment('自增id');
            $table->bigInteger('merchant_medicine_id')->default(0)->comment('药品id');
            $table->bigInteger('merchant_id')   ->default(0) ->comment('商家id');
            $table->string('name')              ->default('')->comment('药品名称');
            $table->string('desc')              ->default('')->comment('描述');
            $table->string('upc')               ->default('')->comment('条形码');
            $table->string('sku_ssn')           ->default('')->comment('内部库存编号');
            $table->string('approval_number')   ->default('')->comment('批准文号');
            $table->string('specification')     ->default('')->comment('规格');
            $table->bigInteger('thumb_id')         ->default(0)    ->comment('商品封面图');
            $table->decimal('selling_price')    ->default(0)->comment('销售价格');//商家自定义
            $table->integer('stock')            ->default(0)->comment('库存');//商家自定义
            $table->integer('classify_id')      ->default(0)   ->comment('');
            $table->string('manufacturer')      ->default('')   ->comment('生产厂商名称');
            $table->string('manufacturer_address')->default('')   ->comment('生产厂商地址');
            $table->string('manufacturer_contact')->default('')   ->comment('生产厂商联系方式');
            $table->string('electronic_regulatory_code') ->default('')   ->comment('电子监管码');
            $table->text('usage_and_dosage')    ->nullable()   ->comment('用法用量');
            $table->text('indications')         ->nullable()   ->comment('适应症');
            $table->string('adapt_to_the_crowd')->default('')   ->comment('适应人群');
            $table->string('component')         ->default('')   ->comment('成分');
            $table->text('adverse_reactions')   ->nullable()   ->comment('不良反应');
            $table->text('contraindications')   ->nullable()   ->comment('禁忌');
            $table->text('precautions')         ->nullable()   ->comment('注意事项');
            $table->text('interaction')         ->nullable()   ->comment('药物相互作用');
            $table->text('medication_for_children') ->nullable()   ->comment('儿童用药');
            $table->text('medication_for_pregnancy_x_lactation') ->nullable()   ->comment('妊娠与哺乳用药');
            $table->text('medication_for_aged') ->nullable()   ->comment('老年人用药');
            $table->string('properties')        ->default('')   ->comment('性状');
            $table->string('packing')           ->default('')   ->comment('包装');
            $table->string('dosage_form')       ->default('')   ->comment('剂型');
            $table->string('storage')           ->default('')   ->comment('贮藏');
            $table->text('pharmacological_action') ->nullable()   ->comment('药理作用');
            $table->string('expiry_date')       ->default('')   ->comment('有效期');
            $table->mediumText('detail')        ->nullable()          ->comment('详情（富文本）');
//            $table->integer('is_shop')          ->default(0)    ->comment('是否上架，0：否 1：是');
//            $table->integer('sort')             ->default(0)    ->comment('商品排序，整数，数字越低排序越前');
            $table->text('other_attribute_array')->nullable()   ->comment('其他属性数组（json_encoded）');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
//        Schema::dropIfExists('orders');
    }
}
